package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.po.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-07
 */
@RestController("learningLessonController")
@RequestMapping("/lessons")
@RequiredArgsConstructor
@Api(tags = "学习-课程表相关接口")
public class LearningLessonController {
    private final ILearningLessonService learningLessonService;

    @GetMapping("/page")
    @ApiOperation("分页查询课程表信息")
    public PageDTO<LearningLessonVO> queryLessonPage(PageQuery pageQuery) {

        return learningLessonService.queryLessonPage(pageQuery);
    }

    @GetMapping("/now")
    @ApiOperation("查询当前课程")
    public LearningLessonVO queryNowLesson() {
        return learningLessonService.queryNowLesson();
    }

    @DeleteMapping("/{courseId}")
    @ApiOperation("删除过期的课程表信息")
    public void removeBycourseId(@PathVariable Long courseId) {
        learningLessonService.removeByCourseId(courseId);
    }


    @GetMapping("/{courseId}/count")
    @ApiOperation("查询课程学习人数")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    @GetMapping("/{courseId}/valid")
    @ApiOperation("查询课程是否有效")
    public Long isLessonValid(@PathVariable("courseId") Long courseId) {
        return learningLessonService.isLessonValid(courseId);
    }


    @GetMapping("/{courseId}")
    @ApiOperation("查询课程状态")
    public LearningLessonVO queryStatusByCourseId(@PathVariable Long courseId) {
        return learningLessonService.queryStatusByCourseId(courseId);
    }

    @PostMapping("/plans")
    @ApiOperation("创建学习计划")
    public void createPlan(@RequestBody LearningPlanDTO dto) {
        learningLessonService.createPlan(dto.getCourseId(), dto.getFreq());
    }

    @GetMapping("/plans")
    @ApiOperation("分页查询学习计划")
    public LearningPlanPageVO queryPlanPage(PageQuery pageQuery) {
        return learningLessonService.queryPlanPage(pageQuery);
    }
}
